import { defineConfig, loadEnv } from "vite"
import vue from "@vitejs/plugin-vue"
import { resolve as pathResolve } from "path"

export default ({ mode }) => {
  const root = process.cwd()
  return defineConfig({
    root: root,
    base: "./",
    plugins: [vue()],
    resolve: {
      alias: {
        "@": pathResolve(process.cwd(), "./src"),
      },
    },
    // 打包配置
    build: {
      outDir: "dist", //指定输出路径
      minify: "terser", // 混淆器，terser构建后文件体积更小
    },
    server: {
      cors: true, // 默认启用并允许任何源
      open: true, // 在服务器启动时自动在浏览器中打开应用程序
      //反向代理配置，注意rewrite写法，开始没看文档在这里踩了坑
      proxy: {
        "/api": {
          target: "http://localhost:7710", //代理接口
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
    },
  })
}
